package Assets.Controls
{
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.filters.GlowFilter;
	
	import mx.containers.Canvas;
	import mx.controls.Button;
	import mx.controls.Label;
	import mx.controls.TextArea;
	import mx.controls.TextInput;
	import mx.core.Window;
	
	public class AddEditContentWindow
	{
		private var caller_string:String;
		private var selectedModuleIndex:int;
		private var selectedLessonIndex:int;
		private var caller_object:Object;
		private var callerMessage_string:String;
		
		private var window:Window;
		private var canvas:Canvas;
		
		private	var name_label:Label = new Label;
		private	var discription_label:Label = new Label;
		private	var editPass_label:Label = new Label;
		private var editPass_textInput:TextInput = new TextInput;
		private var instructorPass_textInput:TextInput = new TextInput;
		private	var instructorPass_label:Label = new Label;
		private	var name_textInput:TextInput = new TextInput;
		private	var discription_textArea:TextArea = new TextArea;
			
		private	var OK_button:Button=new Button;
		private	var CANCEL_button:Button=new Button;
	
		private var heightIncrement:int=0;
		public function AddEditContentWindow(caller:String,callerMessage:String, selectedModuleIndex:int, selectedLessonIndex:int, callerObj:Object)
		{
			this.caller_string=caller;
			this.callerMessage_string=callerMessage;
			this.selectedModuleIndex=selectedModuleIndex;
			this.selectedLessonIndex=selectedLessonIndex;
			//this.nativeWindow_object = container;
			this.caller_object=callerObj;
			
			this.window = new Window;
			this.window.maximizable=false;
			this.window.minimizable=true;
			this.window.resizable=false;
			this.window.type="normal";
			
			this.canvas=new Canvas;
			
			
			name_label.x = 10;
			name_label.y=5;
			name_label.text="Name";
			this.canvas.addChild(this.name_label);
			
			name_textInput.x=80;
			name_textInput.y=5;
			this.name_textInput.width = 300;
			name_textInput.editable=true;
			this.canvas.addChild(this.name_textInput);
			
			discription_label.x = 10;
			discription_label.y=30;
			discription_label.text="Discription";
			this.canvas.addChild(this.discription_label);
			
			discription_textArea.x=10;
			discription_textArea.y=60;
			discription_textArea.width = 400;
			discription_textArea.height = 150;
			discription_textArea.editable=true;
			this.canvas.addChild(this.discription_textArea);
			
			if(this.caller_string=="Lesson")
			{
				this.heightIncrement=90;
				editPass_label.x = 10;
				editPass_label.y=230;
				editPass_label.text="EditPassword";
				this.canvas.addChild(this.editPass_label);
			
				editPass_textInput.x=130;
				editPass_textInput.y=230;
				editPass_textInput.editable=true;
				this.canvas.addChild(this.editPass_textInput);
			
				instructorPass_label.x = 10;
				instructorPass_label.y=270;
				instructorPass_label.text="Instructor Password";
				this.canvas.addChild(this.instructorPass_label);
				
				instructorPass_textInput.x=130;
				instructorPass_textInput.y=270;
				instructorPass_textInput.editable=true;
				this.canvas.addChild(this.instructorPass_textInput);
				
			}
			
			CANCEL_button.label="CANCEL";
			CANCEL_button.x = 330;
			CANCEL_button.y = 230+this.heightIncrement;
			CANCEL_button.filters = [new GlowFilter(0xff0000)];
			CANCEL_button.addEventListener(MouseEvent.CLICK, this.changeCancel);
			this.canvas.addChild(this.CANCEL_button);
			
			OK_button.label="OK";
			OK_button.x = 150;
			OK_button.y = 230 + this.heightIncrement;
			this.OK_button.width=80;
			OK_button.filters = [new GlowFilter(0x00ff00)];
			OK_button.addEventListener(MouseEvent.CLICK, this.changeOK)
			this.canvas.addChild(this.OK_button);
			
			this.window.width=450;
			this.window.height=290+this.heightIncrement;//380
			
			this.canvas.width=445;
			this.canvas.height=270+this.heightIncrement;//360
			this.window.addChild(this.canvas);
			
			//this.nativeWindow_object.enabled = false;
			this.window.open(true);
			
			this.window.addEventListener(Event.CLOSE, this.addEditContentWindowClosed);
		}
		
		private function addEditContentWindowClosed(event:Event):void
		{
			var infoObj_object:Object = new Object;
			//this.nativeWindow_object.enabled = true;
			infoObj_object.message = "changeCancelled";
			this.sendInfoToCaller(infoObj_object);
		}
		
		private function changeOK(event:MouseEvent):void
		{
			var infoObj_object:Object=new Object;
			
			switch (this.callerMessage_string)
			{
				case "AddLesson":
					infoObj_object.message ="createNewLesson";
					infoObj_object.selectedModuleIndex=this.selectedModuleIndex;
					infoObj_object.selectedLessonIndex=this.selectedLessonIndex;
					infoObj_object.editPass = this.editPass_textInput.text.toString();
					infoObj_object.instructorPass = this.instructorPass_textInput.text.toString();
					break;
				
				case "EditLesson":
					infoObj_object.message ="editLessonMetadata";
					infoObj_object.selectedModuleIndex=this.selectedModuleIndex;
					infoObj_object.selectedLessonIndex=this.selectedLessonIndex;
					infoObj_object.editPass = this.editPass_textInput.text.toString();
					infoObj_object.instructorPass = this.instructorPass_textInput.text.toString();
					break;
				
				
				case "AddModule":
					infoObj_object.message = "createNewModule";
					infoObj_object.selectedModuleIndex = this.selectedModuleIndex;
					break;
				
				case "EditModule":
					infoObj_object.message = "editModuleMetadata";
					infoObj_object.selectedModuleIndex = this.selectedModuleIndex;
					break;
				
			}
			//infoObj_object.message = "createNewModule";
					
			infoObj_object.name = this.name_textInput.text.toString();
			infoObj_object.discription = this.discription_textArea.text.toString();
			
			this.window.close();
			this.sendInfoToCaller(infoObj_object);
		}
		
		private function changeCancel(event:MouseEvent):void
		{
			this.window.close();
			var infoObj_object:Object = new Object;
			//this.nativeWindow_object.enabled = true;
			infoObj_object.message = "changeCancelled";
			this.sendInfoToCaller(infoObj_object);
		}
		
		private function sendInfoToCaller(infoObj_obj:Object):void
		{
			this.caller_object.incomingMessageGateway(infoObj_obj);
		}
		

	}
}